---
import { getCollection, getEntry } from 'astro:content';
import Layout from '../../layouts/Layout.astro';

const { slug } = Astro.params;
if (!slug) throw new Error('Slug not found');
const post = await getEntry('posts', slug);

if (!post) throw new Error('No post found for this slug');
const { Content } = await post.render();

// Generate static pages
export async function getStaticPaths() {
  const posts = await getCollection('posts');
  return posts.map(post => ({ params: { slug: post.slug } }));
}
---

<Layout title={post.data.title}>
  <h1>{post.data.title}</h1>
  <Content />
</Layout>
